fix(field): add preserveOriginalLabel prop to SearchSelect #8919
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BREAKING CHANGE: None
close #8918
出现问题的原因:
在多选且开启 labelInValue 的情况,onChange 的时候会使用 getMergeValue 来合并最终数据
pro-components/packages/field/src/components/Select/SearchSelect/index.tsx
Line 155 in 21ce755
代码如下:
渲染的下拉列表里的 label 是经过optionItemRender 处理过的用关键词匹配加上高亮的 ReactNode (https://github.com/ant-design/pro-components/blob/21ce755745c1b5fa26415cd1dcc1a8ac8ed2c159/packages/field/src/components/Select/index.tsx#L531),
这里 item 里的 label 会把 dataItem 的 label 覆盖掉,就导致最终填充到输入框的内容也是带高亮样式的
这个 PR 的解决方法:
添加了一个属性 preserveOriginalLabel, 开启这个属性后,在开启 labelInValue 的时候,触发 onChange 的时候的 value 里就用原始的 options 里的 label,关闭后就用经过 optionItemRender 处理过的实际展示出来的 label